package com.alks.function.controller.chengKong;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.common.utils.MinIoUtil;
import com.alks.entity.data.entity.KfStylePhoto;
import com.alks.entity.data.entity.KfStyleProcessData;
import com.alks.entity.data.entity.YfStyleColorDetail;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.request.chengKong.StyleAddRequest;
import com.alks.function.data.request.chengKong.StyleBasicRequest;
import com.alks.function.data.request.chengKong.StyleNumberAddRequest;
import com.alks.function.service.chengKong.DevelopmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@ApiRestController("/development")
@Api(tags = {"成控部-物料管理作业-开发型体建档"})
@Slf4j
public class DevelopmentController {

    @Autowired
    private DevelopmentService developmentService;

    @WebLogger
    @PostMapping("/getStyleAdd")
    @ApiOperation(value = "新增作业",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStyleAdd(@RequestBody Map<String,String> map){
        return  developmentService.getStyleAdd(map);
    }

    @WebLogger
    @PostMapping("/getStyleBasicAdd")
    @ApiOperation(value = "保存",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStyleBasicAdd(@RequestBody StyleAddRequest request){
        return developmentService.getStyleBasicAdd(request);
    }

    @WebLogger
    @PostMapping("/getStyleNumber")
    @ApiOperation(value = "取号码",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStyleNumber(@RequestBody Map<String,String> map){
        return developmentService.getStyleNumber(map);
    }

    @WebLogger
    @PostMapping("/getStyleNumberAdd")
    @ApiOperation(value = "取号码插入",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStyleNumberAdd(@RequestBody StyleNumberAddRequest request){
        return developmentService.getStyleNumberAdd(request);
    }

    @WebLogger
    @PostMapping("/getStyleBasicList")
    @ApiOperation(value = "基本制具资料查询",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStyleBasicList(@RequestBody StyleBasicRequest request){
        return developmentService.getStyleBasicList(request);
    }

    @WebLogger
    @GetMapping("/getStyleType")
    @ApiOperation(value = "制具资料查询",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStyleType(@RequestParam String styleNo){
        return developmentService.getStyleType(styleNo);
    }

    @WebLogger
    @PostMapping("/getStyleSizeList")
    @ApiOperation(value = "配码资料查询",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStyleSizeList(@RequestBody Map<String,String> map){
        return developmentService.getStyleSizeList(map);
    }

    @WebLogger
    @PostMapping("/getStylePhotoList")
    @ApiOperation(value = "型体配色资料查询",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStylePhotoList(@RequestBody Map<String,String> map){
        return developmentService.getStylePhotoList(map);
    }

    @WebLogger
    @PostMapping("/getStyleBasicCopyAdd")
    @ApiOperation(value = "复制",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStyleBasicCopyAdd(@RequestBody StyleAddRequest request){
        return developmentService.getStyleBasicCopyAdd(request);
    }

    @WebLogger
    @PostMapping("/getStyleBasicAllDel")
    @ApiOperation(value = "整单删除",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStyleBasicAllDel(@RequestBody Map<String,String> map){
        return developmentService.getStyleBasicAllDel(map);
    }

    @WebLogger
    @PostMapping("/getChangeOfOrderMaker")
    @ApiOperation(value = "制单员变更",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getChangeOfOrderMaker(@RequestBody Map<String,String> map){
        return developmentService.getChangeOfOrderMaker(map);
    }

    @WebLogger
    @PostMapping("/getInspect/{choose}")
    @ApiOperation(value = "0检验/1取消检验",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getInspect(@RequestBody List<String> styleNoList, @PathVariable("choose") Integer choose){
        return developmentService.getInspect(styleNoList,choose);
    }

    @PostMapping("/updateStylePhoto")
    @ApiOperation(value = "上传图片",tags = {"成控部-物料管理作业-开发型体建档"})
    @WebLogger
    public ResponseInfo updateStylePhoto(@RequestParam(value = "file") MultipartFile file, String photoPath) {
        return developmentService.updateStylePhoto(file,photoPath);
    }

    @Resource
    MinIoUtil minIoUtil;

    @WebLogger
    @ApiOperation(value = "图片下载",tags = {"成控部-物料管理作业-开发型体建档"})
    @GetMapping("/download")
    public void download(@RequestParam(name = "fileName") String fileName,
                         HttpServletResponse response){
        try {
            //对路径进行切割
            int index = fileName.indexOf("/photo");
            fileName = fileName.substring(index + "photo".length() + 1);
            minIoUtil.download("photo",fileName,response);
        }catch (Exception e){
            log.error("图片下载失败!");
            e.printStackTrace();
        }
    }

    @WebLogger
    @PostMapping("/getStylePhotoAdd")
    @ApiOperation(value = "型体配色资料添加",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStylePhotoAdd(@RequestBody YfStyleColorDetail styleColorDetail){
        return developmentService.getStylePhotoAdd(styleColorDetail);
    }

    @WebLogger
    @PostMapping("/getStylePhotoDel")
    @ApiOperation(value = "型体配色资料删除",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStylePhotoDel(@RequestBody YfStyleColorDetail styleColorDetail){
        return developmentService.getStylePhotoDel(styleColorDetail);
    }

    @WebLogger
    @PostMapping("/getStylePhotoUpdate")
    @ApiOperation(value = "型体配色资料修改",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStylePhotoUpdate(@RequestParam@ApiParam("修改前型体") String styleNo,
                                            @RequestParam@ApiParam("修改前颜色") String styleColor,
                                            @RequestBody YfStyleColorDetail styleColorDetail){
        return developmentService.getStylePhotoUpdate(styleNo,styleColor,styleColorDetail);
    }

    @WebLogger
    @PostMapping("/getStyleProcessData")
    @ApiOperation(value = "查询工艺数据",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStyleProcessData(@RequestParam String style){
        return developmentService.getStyleProcessData(style);
    }

    @WebLogger
    @PostMapping("/getStyleProcessDataUpdate")
    @ApiOperation(value = "工艺数据修改",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStyleProcessDataUpdate(@RequestBody KfStyleProcessData  kfStyleProcessData){
        return developmentService.getStyleProcessDataUpdate(kfStyleProcessData);
    }

    @WebLogger
    @PostMapping("/getStyleProcessDataAdd")
    @ApiOperation(value = "工艺数据添加",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStyleProcessDataAdd(@RequestBody KfStyleProcessData  kfStyleProcessData){
        return developmentService.getStyleProcessDataAdd(kfStyleProcessData);
    }

    @WebLogger
    @PostMapping("/getStyleProcessDataDel")
    @ApiOperation(value = "工艺数据删除",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStyleProcessDataDel(@RequestBody KfStyleProcessData  kfStyleProcessData){
        return developmentService.getStyleProcessDataDel(kfStyleProcessData);
    }

    @WebLogger
    @PostMapping("/getStylePhoto")
    @ApiOperation(value = "大图细节补充数据",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStylePhoto(@RequestParam String style,@RequestParam String styleColor){
        return developmentService.getStylePhoto(style,styleColor);
    }

    @WebLogger
    @PostMapping("/getStylePhotoUpdate2")
    @ApiOperation(value = "大图细节补充修改",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStylePhotoUpdate2(@RequestBody KfStylePhoto  kfStylePhoto){
        return developmentService.getStylePhotoUpdate2(kfStylePhoto);
    }

    @WebLogger
    @PostMapping("/getStylePhotoAdd2")
    @ApiOperation(value = "大图细节补充添加",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStylePhotoAdd2(@RequestBody KfStylePhoto  kfStylePhoto){
        return developmentService.getStylePhotoAdd2(kfStylePhoto);
    }

    @WebLogger
    @PostMapping("/getStylePhotoDelete")
    @ApiOperation(value = "大图细节补充删除",tags = "成控部-物料管理作业-开发型体建档")
    public ResponseInfo getStylePhotoDelete(@RequestBody KfStylePhoto kfStylePhoto){
        return developmentService.getStylePhotoDelete(kfStylePhoto);
    }

}
